//
//  OperationBillDetailGoodCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/11/9.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "OperationBillDetailGoodCell.h"

@interface OperationBillDetailGoodCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *weightTitleLab;
@property (nonatomic, strong) UILabel *weightLab;
@property (nonatomic, strong) UILabel *tiJiTitleLab;
@property (nonatomic, strong) UILabel *tiJiLab;
@property (nonatomic, strong) UILabel *pieceTitleLab;
@property (nonatomic, strong) UILabel *pieceLab;
@property (nonatomic, strong) UILabel *countTitleLab;
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UIButton *lookBtn;

@end

@implementation OperationBillDetailGoodCell

+ (instancetype)OperationBillDetailGoodCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"OperationBillDetailGoodCell";
    OperationBillDetailGoodCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[OperationBillDetailGoodCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.titleLab = [UILabel new];
        self.titleLab.textColor = HexColor(0x2B2C44);
        self.titleLab.font = [UIFont systemFontOfSize:18];
        [self.bgView addSubview:self.titleLab];
        
        self.weightTitleLab = [UILabel new];
        self.weightTitleLab.textColor = HexColor(0x9C9DB3);
        self.weightTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.weightTitleLab];
        
        self.weightLab = [UILabel new];
        self.weightLab.textColor = HexColor(0x2B2C44);
        self.weightLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.weightLab];
        
        self.tiJiTitleLab = [UILabel new];
        self.tiJiTitleLab.textColor = HexColor(0x9C9DB3);
        self.tiJiTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.tiJiTitleLab];
        
        self.tiJiLab = [UILabel new];
        self.tiJiLab.textColor = HexColor(0x2B2C44);
        self.tiJiLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.tiJiLab];
        
        self.pieceTitleLab = [UILabel new];
        self.pieceTitleLab.textColor = HexColor(0x9C9DB3);
        self.pieceTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.pieceTitleLab];
        
        self.pieceLab = [UILabel new];
        self.pieceLab.textColor = HexColor(0x2B2C44);
        self.pieceLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.pieceLab];
        
        self.countTitleLab = [UILabel new];
        self.countTitleLab.textColor = HexColor(0x9C9DB3);
        self.countTitleLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.countTitleLab];
        
        self.countLab = [UILabel new];
        self.countLab.textColor = HexColor(0x2B2C44);
        self.countLab.font = [UIFont systemFontOfSize:14];
        [self.bgView addSubview:self.countLab];
        
        self.lookBtn = [UIButton new];
        [self.lookBtn setTitle:@"货物明细清单" forState:0];
        [self.lookBtn setTitleColor:Color_ThemeColor forState:0];
        self.lookBtn.titleLabel.font = BoldFontOfSize(16);
        [self.lookBtn setImage:[UIImage imageNamed:@"icon_form"] forState:0];
        [self.lookBtn addTarget:self action:@selector(lookClick) forControlEvents:UIControlEventTouchUpInside];
        [self.lookBtn setBackgroundColor:HexColorA(0x3D68EB, 0.1)];
        self.lookBtn.layer.masksToBounds = YES;
        self.lookBtn.layer.cornerRadius = 4;
        [self.bgView addSubview:self.lookBtn];
    }
    return self;
}

- (void)lookClick {
    if (self.goodBlock) {
        self.goodBlock();
    }
}

-(void)setModel:(OperationBillDetailModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 2 * self.bgView.nim_left;
    
    self.titleLab.text = @"货物信息";
    [self.titleLab sizeToFit];
    self.titleLab.nim_left = 15;
    self.titleLab.nim_top = 20;
    
    self.weightTitleLab.text = @"装载重量(kg)：";
    [self.weightTitleLab sizeToFit];
    self.weightTitleLab.nim_left = 15;
    self.weightTitleLab.nim_top = self.titleLab.nim_bottom + 10;
    
    self.weightLab.nim_left = self.weightTitleLab.nim_right;
    self.weightLab.nim_width = self.bgView.nim_width * 0.5 - self.weightLab.nim_left;
    self.weightLab.text = [NSString stringWithFormat:@"%@",self.model.total_weight];
    [self.weightLab sizeToFit];
    self.weightLab.nim_width = self.bgView.nim_width * 0.5 - self.weightLab.nim_left;
    self.weightLab.nim_centerY = self.weightTitleLab.nim_centerY;
    
    self.pieceTitleLab.text = @"装载件数：";
    [self.pieceTitleLab sizeToFit];
    self.pieceTitleLab.nim_left = self.bgView.nim_width * 0.5;
    self.pieceTitleLab.nim_top = self.titleLab.nim_bottom + 10;
    
    self.pieceLab.nim_left = self.pieceTitleLab.nim_right;
    self.pieceLab.nim_width = self.bgView.nim_width - 15 - self.pieceLab.nim_left;
    self.pieceLab.text = self.model.goods_jnum;
    [self.pieceLab sizeToFit];
    self.pieceLab.nim_width = self.bgView.nim_width - 15 - self.pieceLab.nim_left;
    self.pieceLab.nim_centerY = self.pieceTitleLab.nim_centerY;
    
    
    self.tiJiTitleLab.text = @"装载体积(m³)：";
    [self.tiJiTitleLab sizeToFit];
    self.tiJiTitleLab.nim_left = 15;
    self.tiJiTitleLab.nim_top = self.weightTitleLab.nim_bottom + 5;
    
    self.tiJiLab.nim_left = self.tiJiTitleLab.nim_right;
    self.tiJiLab.nim_width = self.bgView.nim_width * 0.5 - self.tiJiLab.nim_left;
    self.tiJiLab.text = [NSString stringWithFormat:@"%@",self.model.total_volume];
    [self.tiJiLab sizeToFit];
    self.tiJiLab.nim_width = self.bgView.nim_width * 0.5 - self.tiJiLab.nim_left;
    self.tiJiLab.nim_centerY = self.tiJiTitleLab.nim_centerY;
    
    self.countTitleLab.text = @"装载货物数量：";
    [self.countTitleLab sizeToFit];
    self.countTitleLab.nim_left = self.bgView.nim_width * 0.5;
    self.countTitleLab.nim_top = self.tiJiTitleLab.nim_top;
    
    self.countLab.nim_left = self.countTitleLab.nim_right;
    self.countLab.nim_width = self.bgView.nim_width - 15 - self.countLab.nim_left;
    self.countLab.text = self.model.goods_num;
    [self.countLab sizeToFit];
    self.countLab.nim_width = self.bgView.nim_width - 15 - self.countLab.nim_left;
    self.countLab.nim_centerY = self.countTitleLab.nim_centerY;
    
    self.lookBtn.frame = CGRectMake(15, self.tiJiTitleLab.nim_bottom + 10, self.bgView.nim_width - 30, 42);
    
    self.bgView.nim_height = self.lookBtn.nim_bottom + 15;
    
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
